{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import arcpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "sr = arcpy.SpatialReference(4326)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "sd = arcpy.Point(116.5930544,40.0795454)\n",
    "dx = arcpy.Point(116.4168081, 39.5129736)\n",
    "line = arcpy.Polyline(inputs=arcpy.Array([sd,dx]),\n",
    "spatial_reference=sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "center = line.centroid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Point (116.50493125, 39.796259500000005, #, #)>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "center"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "pnt = arcpy.Point(116.51,39.796)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "fst_pnt = arcpy.PointGeometry(inputs=line.firstPoint,spatial_reference=sr)\n",
    "lst_pnt = arcpy.PointGeometry(inputs=line.lastPoint,spatial_reference=sr)\n",
    "cet_pnt = arcpy.PointGeometry(inputs=line.centroid,spatial_reference=sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "起点到指定点的角度距离：(-167.26680776056278, 32273.406653690792)\n",
      "讫点到指定点的角度距离：(14.24997265649848, 32425.699044448065)\n",
      "中点到指定点的角度距离：(93.79548013110833, 435.0796721281546)\n"
     ]
    }
   ],
   "source": [
    "print(f\"起点到指定点的角度距离：{fst_pnt.angleAndDistanceTo(pnt)}\")\n",
    "print(f\"讫点到指定点的角度距离：{lst_pnt.angleAndDistanceTo(pnt)}\")\n",
    "print(f\"中点到指定点的角度距离：{cet_pnt.angleAndDistanceTo(pnt)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.004917060517002384"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line.distanceTo(pnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.11 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "06b308fdbfd5979111721ebbf4de1ae2cbf405c7740d4ab5c57cb4c3e518bed6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
